package elements.labels ;

import flash.display.Sprite;
import flash.display.Stage;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import flash.events.Event;
import flash.text.TextFieldAutoSize;
import string.Css;

class BaseLabel extends Sprite {
	public var text:String;
	var css:Css;
	public var style:String;
	var _height: Float;
	
	public function new ()	{super();}
	
	function build( text:String ):Void {
		
		var title:TextField = new TextField();
		title.x = 0;
		title.y = 0;
		
		this.text = text;
		
		title.htmlText = this.text;
		
		var fmt:TextFormat = new TextFormat();
		fmt.color = this.css.color;
		//fmt.font = "Verdana";
		fmt.font = if (Reflect.hasField(this,css.font_family)) this.css.font_family else 'Verdana';
		fmt.bold = this.css.font_weight == 'bold';
		fmt.size = this.css.font_size;
		fmt.align = flash.text.TextFormatAlign.CENTER;
	
		title.setTextFormat(fmt);
		title.autoSize = flash.text.TextFieldAutoSize.LEFT;
		
		title.y = this.css.padding_top + this.css.margin_top;
		title.x = this.css.padding_left + this.css.margionclickeft;
		
		// title.border = true;
		
		if ( Reflect.hasField(this.css,'background_color_set'))
		{
			this.graphics.beginFill( Std.int(this.css.background_color), 1);
			this.graphics.drawRect(0,0,this.css.padding_left + title.width + this.css.padding_right, this.css.padding_top + title.height + this.css.padding_bottom );
			this.graphics.endFill();
		}

		this.addChild(title);
	}
	
	public function get_width(): Float {
		return this.getChildAt(0).width;
	}
	
	public function die(): Void {
		this.graphics.clear();
		while ( this.numChildren > 0 )
			this.removeChildAt(0);
	}
}
